home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / utilities / pu740.dms / pu740.adf / Rexx.lha / BatchConvert.isrx < prev    next >
Text File  |  1995-03-01  |  7KB  |  294 lines

  1. /* ImageStudio ARexx script **************************************/
  2.  
  3. /* Allow commands to return results */
  4.  
  5. options results
  6.  
  7. /* On error, goto ERROR:. Comment out this line if you wish to */
  8. /* perform your own error checking. */
  9.  
  10. signal on error
  11.  
  12. /* BEGIN PROGRAM *************************************************/
  13.  
  14. /* Warn the user if they are about to overwrite their current project */
  15.  
  16. IMAGEINFO_GET STEM imageinfo.
  17.  
  18. if imageinfo.changed == 1 then
  19.     REQUEST_MESSAGE TEXT '"Project has changed, continue?"',
  20.         BUTTONTEXT '"OK|Cancel"' AUTOCANCEL
  21.  
  22. /* Choose source files */
  23.  
  24. REQUEST_MULTIFILE TITLE '"Choose source files..."' STEM srcfiles.
  25.  
  26. /* Use separate destination directory ? */
  27.  
  28. REQUEST_MESSAGE TEXT '"Use different destination directory?"',
  29.     BUTTONTEXT '"Yes|No|Cancel"' AUTOCANCEL
  30.  
  31. if result == 1 then
  32.     REQUEST_DIR TITLE '"Choose destination directory..."' VAR destdir
  33. else
  34.     destdir = ':NONE:'
  35.  
  36. REQUEST_LIST TITLE '"Choose output format..."' STRINGS,
  37.     '"IFF-ILBM"',
  38.     '"BMP"',
  39.     '"EPS"',
  40.     '"JPEG"',
  41.     '"PCX"',
  42.     '"Targa"' STEM saveformat.
  43.  
  44. /* Set up a blank ARGS string, which we can add to */
  45.  
  46. saveargs = 'ARGS "'
  47.  
  48. /* Get any IFF-ILBM args ? */
  49.  
  50. if saveformat.string == 'IFF-ILBM' then do
  51.     /* Get a subformat */
  52.  
  53.     REQUEST_MESSAGE TEXT '"Choose ILBM format..."' BUTTONTEXT,
  54.         '"As buffer|HAM6|HAM8|EHB|Cancel"' AUTOCANCEL
  55.  
  56.     /* Store subformat */
  57.  
  58.     if result == 2 then
  59.         saveargs = saveargs||'SUBFORMAT HAM6'
  60.     else if result == 3 then
  61.         saveargs = saveargs||'SUBFORMAT HAM8'
  62.     else if result == 4 then
  63.         saveargs = saveargs||'SUBFORMAT EHB'
  64.  
  65.     /* Get the dither if not saving as buffer */
  66.  
  67.     if result ~= 1 then do
  68.         REQUEST_MESSAGE TEXT '"Choose ILBM dither..."' BUTTONTEXT,
  69.             '"None|Floyd-Steinberg|Cancel"' AUTOCANCEL
  70.  
  71.         /* Store the dither */
  72.  
  73.         if result == 2 then
  74.             saveargs = saveargs||' DITHER FS'
  75.  
  76.         end
  77.  
  78.     /* Ask whether should set screenmode of images */
  79.  
  80.     REQUEST_MESSAGE TEXT '"Set screenmode of images?"',
  81.         BUTTONTEXT '"Yes|No|Cancel"' AUTOCANCEL
  82.  
  83.     if result == 1 then do
  84.         setscreenmode = 1
  85.  
  86.         REQUEST_SCREENMODE STEM screenmode.
  87.  
  88.         imagescreenmode = screenmode.modeid
  89.  
  90.         end
  91.     else
  92.         setscreenmode = 0
  93.     end
  94. else if saveformat.string == 'EPS' then do
  95.     /* Get the DPI of the image */
  96.  
  97.     REQUEST_STRING TEXT1 '"Enter the DPI resolution of"',
  98.         TEXT2 '"the EPS files to be saved:"',
  99.         STRING 300 VAR dpiinfo
  100.  
  101.     saveargs = saveargs||dpiinfo
  102.  
  103.     /* Ask whether to save as colour or greyscale */
  104.  
  105.     REQUEST_MESSAGE TEXT '"Greyscale or colour EPS?"' BUTTONTEXT,
  106.         '"Greyscale|Colour|Cancel"' AUTOCANCEL
  107.  
  108.     if result == 2 then
  109.         saveargs = saveargs||' COLOUR'
  110.  
  111.     end
  112. else if saveformat.string == 'JPEG' then do
  113.     /* Get the DPI of the image */
  114.  
  115.     REQUEST_STRING TEXT1 '"Enter the JPEG quality setting"',
  116.         TEXT2 '"for the files to be saved."',
  117.         TEXT3 '"(Valid values 25 to 100):"',
  118.         STRING 75 VAR qualityinfo
  119.  
  120.     saveargs = saveargs||qualityinfo
  121.  
  122.     /* Ask whether to save as colour or greyscale */
  123.  
  124.     REQUEST_MESSAGE TEXT '"Greyscale or colour JPEG?"' BUTTONTEXT,
  125.         '"Greyscale|Colour|Cancel"' AUTOCANCEL
  126.  
  127.     if result == 1 then
  128.         saveargs = saveargs||' GREYSCALE'
  129.  
  130.     end
  131.  
  132. /* We may or may not have created an ARGS string. If we have, lets */
  133. /* finish it off, else lets delete it */
  134.  
  135. if saveargs == 'ARGS "' then
  136.     saveargs = ''
  137. else
  138.     saveargs = saveargs||'"'
  139.  
  140. /* Rename filenames ? */
  141.  
  142. REQUEST_MESSAGE TEXT '"Rename filenames ?"' BUTTONTEXT,
  143.     '"Yes|No|Cancel"' AUTOCANCEL
  144.  
  145. if result == 1 then do
  146.     /* Set the rename files */
  147.  
  148.     renamefiles = 1
  149.  
  150.     /* Get the rename pattern */
  151.  
  152.     REQUEST_STRING TEXT1 '"Choose the filename extension. For"',
  153.         TEXT2 '"example: . .ILBM would rename all"',
  154.         TEXT3 '"files to .ILBM, see docs for more info"',
  155.         STRING '". .'||saveformat.string||'"',
  156.         VAR renamestring
  157.     end
  158. else
  159.     renamefiles = 0
  160.  
  161. /* If we're renaming, we should ask if they want the source file */
  162. /* deleted. If we're not renaming, we should warn the user that */
  163. /* the source file will be overwritten. */
  164.  
  165. if renamefiles == 1 then do
  166.     REQUEST_MESSAGE TEXT '"Delete source files ?"',
  167.         BUTTONTEXT '"Yes|No|Cancel"' AUTOCANCEL
  168.  
  169.     if result == 1 then
  170.         deletesource = 1
  171.     else
  172.         deletesource = 0
  173.     end
  174. else if renamefiles == 0 & destdir == ':NONE:' then
  175.     REQUEST_MESSAGE TEXT '"WARNING : Source files will\nbe overwritten."',
  176.         BUTTONTEXT '"OK|Cancel"' AUTOCANCEL
  177.  
  178. /* Loop around and convert all the files */
  179.  
  180. do l = 0 to (srcfiles.files.count - 1)
  181.     /* Open the file */
  182.  
  183.     OPEN FILE '"'srcfiles.files.l'"' FORCE
  184.  
  185.     /* Set the screenmode if neccessary */
  186.  
  187.     if setscreenmode == 1 then
  188.         IMAGEINFO_SET MODEID imagescreenmode
  189.  
  190.     /* Create the output filename */
  191.  
  192.     if destdir ~= ':NONE:' then do
  193.         /* Get the filepart of the source filename */
  194.  
  195.         FILE_SPLIT FILE '"'srcfiles.files.l'"' STEM filesplit.
  196.  
  197.         /* Create the destfile */
  198.  
  199.         FILE_JOIN PATHPART '"'destdir'"',
  200.             FILEPART '"'filesplit.filepart'"' VAR 'destfile'
  201.  
  202.         end
  203.     else
  204.         destfile = srcfiles.files.l
  205.  
  206.     /* Rename file ? */
  207.  
  208.     if renamefiles == 1 then 
  209.         FILE_RENAME FILE '"'destfile'"' renamestring,
  210.             VAR 'destfile'
  211.  
  212.     /* Save the fileout in the new format */
  213.  
  214.     SAVE FILE '"'destfile'"' FORMAT '"'saveformat.string'"',
  215.         saveargs FORCE
  216.  
  217.     /* Delete source file (and icon) if required */
  218.  
  219.     if renamefiles == 1 & deletesource == 1 then do
  220.         /* Make sure hasn't been renamed to same name */
  221.  
  222.         if upper(srcfiles.files.l) == upper(destfile) then
  223.             break
  224.  
  225.         address command 'delete <NIL: >NIL: "'||srcfiles.files.l||'"'
  226.  
  227.         if exists(srcfiles.files.l||'.info') == 1 then
  228.             address command 'delete <NIL: >NIL: "'||,
  229.                 srcfiles.files.l||'.info"'
  230.         end
  231.     end
  232.  
  233.  
  234. /* END PROGRAM ***************************************************/
  235.  
  236. exit
  237.  
  238. /* On ERROR */
  239.  
  240. ERROR:
  241.  
  242. /* If we get here, either an error occurred with the command's */
  243. /* execution or there was an error with the command itself. */
  244. /* In the former case, rc2 contains the error message and in */
  245. /* the latter, rc2 contains an error number. SIGL contains */
  246. /* the line number of the command which caused the jump */
  247. /* to ERROR: */
  248.  
  249. if datatype(rc2,'NUMERIC') == 1 then do
  250.     /* See if we can describe the error with a string */
  251.  
  252.     select
  253.         when rc2 == 103 then
  254.             err_string = "ERROR 103, "||,
  255.                 "out of memory at line "||SIGL
  256.         when rc2 == 114 then
  257.             err_string = "ERROR 114, "||,
  258.                 "bad command template at line "||SIGL
  259.         when rc2 == 115 then
  260.             err_string = "ERROR 115, "||,
  261.                 "bad number for /N argument at line "||SIGL
  262.         when rc2 == 116 then
  263.             err_string = "ERROR 116, "||,
  264.                 "required argument missing at line "||SIGL
  265.         when rc2 == 117 then
  266.             err_string = "ERROR 117, "||,
  267.                 "value after keywork missing at line "||SIGL
  268.         when rc2 == 118 then
  269.             err_string = "ERROR 118, "||,
  270.                 "wrong number of arguments at line "||SIGL
  271.         when rc2 == 119 then
  272.             err_string = "ERROR 119, "||,
  273.                 "unmatched quotes at line "||SIGL
  274.         when rc2 == 120 then
  275.             err_string = "ERROR 120, "||,
  276.                 "line too long at line "||SIGL
  277.         when rc2 == 236 then
  278.             err_string = "ERROR 236, "||,
  279.                 "unknown command at line "||SIGL
  280.         otherwise
  281.             err_string = "ERROR "||rc2||", at line "||SIGL
  282.         end
  283.         end
  284. else if rc2 == 'RC2' then do
  285.     err_string = "ERROR in command at line "||SIGL
  286.     end
  287. else do
  288.         err_string = rc2||", line "||SIGL
  289.         end
  290.  
  291. request_message TEXT '"'err_string'"'
  292.  
  293. exit
  294.